package ru.amse.baltijsky.javascheme.node;

import java.util.Iterator;

/**
 * A node of the schema tree.
 * From such node one can navigate to the sole <i>next</i> node (if present) or to a list of <i>children</i> nodes (if present).
 * A node has access to its only parent.
 * <p/>
 * The parametrization is due to the topology-traversal algorithms using <tt>INode</tt>: to have a generic traversal class
 * and ensure that it walks only the certain concrete implementation of <tt>INode</tt> at a time, we have to do this.
 */
public interface INode<T extends INode> {
    /**
     * Returns the next node for the current node.
     *
     * @return the next node for the current node.
     */
    T getNext();

    /**
     * Indicates whether the node has the next node in the loadTree tree.
     *
     * @return <code>true</code> if a next node exists
     */
    boolean hasNext();

    /**
     * Returns the parent (nesting) node.
     *
     * @return the parent (nesting) node (null if no parents are present).
     */
    T getParent();

    /**
     * Indicates whether the current node has parent (a node that nests the current node).
     *
     * @return <code>true</code> if the current node has a (non-null) parent.
     */
    boolean hasParent();

    /**
     * Returns iterator over the children of the node.
     * A node can have no children at all, then it will be an iterator over an empty collection.
     *
     * @return iterator for the children of the node
     */
    Iterator<T> getChildren();

    /**
     * Determines whether the node has children.
     *
     * @return <tt>true</tt> iff the node has children
     */
    boolean hasChildren();
}